home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter Code.exe / Chapter09 / StartStopPanel.java < prev    next >
Text File  |  2000-08-27  |  1KB  |  64 lines

  1.  
  2. package applets;
  3.  
  4. import shout3d.*;
  5. import shout3d.core.*;
  6. import shout3d.math.*;
  7.  
  8.  
  9. public class StartStopPanel extends Shout3DPanel implements DeviceObserver {
  10.    
  11.    
  12.    TimeSensor timer;
  13.    boolean started = false;
  14.  
  15.    public StartStopPanel (Shout3DApplet applet){
  16.       super(applet);
  17.    }
  18.    
  19.    
  20.    public void customInitialize() {
  21.       addDeviceObserver(this,"MouseInput", null);
  22.       timer =(TimeSensor) getNodeByName("world-TIMER");
  23.  
  24.  
  25.    }
  26.  
  27.    protected void finalize()  { 
  28.       removeDeviceObserver(this,"MouseInput");
  29.  
  30.    }
  31.  
  32.  
  33.    public boolean onDeviceInput(DeviceInput di, Object userData) {
  34.       MouseInput mi = (MouseInput) di;
  35.  
  36.       switch (mi.which){
  37.  
  38.          case MouseInput.DOWN:
  39.          
  40.             //if animation is not started
  41.             if (!started) {
  42.  
  43.                timer.start();
  44.                started = true;   
  45.                return true;
  46.             }
  47.             
  48.  
  49.              //if already started
  50.              else   {
  51.                timer.stop();
  52.                started = false;   
  53.                return true;                              
  54.               }
  55.          
  56.       }//end of switch
  57.  
  58.       return false;
  59.       
  60.    }
  61.  
  62.    
  63.  
  64. } //end of class